package com.example.recite_words.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Get_data {
    public  static  JSONObject getJsonObject(InputStream in) throws IOException {
        //从一个输入流获取json文件
        BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
        StringBuffer sb = new StringBuffer();
        String string = null;
        while ((string = buffer.readLine()) != null){
            sb.append(string).append('\n');
        }
        String s = JSON.toJSONString(sb);
        s = s.replace("/n","");
        s = s.replace("\\n", "");
        s = s.replaceAll("\\\\","");

        s = s.substring(1,s.length() - 1);

        JSONObject jsonObject = JSONObject.parseObject(s);
        return  jsonObject;
    }
}
